Skip to content

PR: Sub Issue 5 - EventManager thread safety fix - #321

Merged
JusterZhu merged 2 commits into
masterfrom
feature/event-threadsafe
May 24, 2026
Merged

JusterZhu merged 2 commits into
masterfrom
feature/event-threadsafe

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Summary

Closes #320

Change

  • Replace double-check locking with \Lazy\ for guaranteed singleton thread safety.

The old code used a non-volatile _instance\ field with classic double-check locking, which can fail under concurrent access on some .NET runtimes. \Lazy\ guarantees exactly-once initialization.

Build

✅ 0 errors

The old EventManager singleton used non-volatile _instance field with
double-check locking pattern, which is not guaranteed thread-safe on all
.NET runtimes. Replaced with Lazy<T> which guarantees thread safety.

Closes #320
Copilot AI review requested due to automatic review settings May 24, 2026 00:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #320 by fixing EventManager singleton initialization to be thread-safe under concurrent access. It replaces a classic double-checked locking implementation (with a non-volatile backing field) with Lazy<EventManager>, which provides guaranteed thread-safe, exactly-once initialization.

Changes:

  • Replace the double-check locking singleton implementation with a Lazy<EventManager>-backed singleton.
  • Simplify the Instance accessor to an expression-bodied property returning _lazy.Value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- AES-encrypted .enc files instead of plaintext .txt
- Dedicated subdirectory: %TEMP%/GeneralUpdate/ipc/
- Auto-deleted after read
- Per-user isolation

Closes #322
@JusterZhu
JusterZhu merged commit 773227a into master May 24, 2026
@JusterZhu
JusterZhu deleted the feature/event-threadsafe branch May 24, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sub Issue 5: EventManager thread safety fix (Lazy<T> singleton)

2 participants